//
//  ViewController.swift
//  TTProduct
//
//  Created by Toj on 1/4/21.
//
import Cocoa
import AliyunOSSiOS
import DiskArbitration

class ViewController: TTViewController {
    private lazy var button: TTButton = {
        let view = TTButton()
        return view
    }()
    private lazy var textScrollView: NSScrollView = {
        let view = NSScrollView()
        view.scrollerStyle = .overlay
        view.scrollerKnobStyle = .dark
        view.autohidesScrollers = true
        view.verticalScrollElasticity = .automatic
        view.documentView = textView
        view.backgroundColor = NSColor.init(hexColor: "#E9EEF2")
        view.drawsBackground = true
        return view
    }()
    
    private lazy var textView: NSTextField = {
        let view = NSTextField()
        view.isBezeled = false
        view.focusRingType = .none
        view.placeholderString = "请输入消息".tt_localized
        view.font = NSFont.systemFont(ofSize: 11)
        view.textColor = NSColor.init(hexColor: "#989A9D")
        view.backgroundColor = .clear
        return view
    }()
    
    var howLong = 0
    @objc func updateSecond() {
        howLong += 1
        print(howLong)
    }
   
    
    private var timer: Timer?
    var aResource: OSSResource?
    override func viewDidLoad() {
        super.viewDidLoad()
        
        view.addSubview(button)
        button.snp.makeConstraints { (make) in
            make.bottom.equalTo(view.snp.bottom).offset(-100)
            make.left.height.width.equalTo(100)
        }

        button.target = self
        button.action = #selector(self.didTapButton)
        button.wantsLayer = true
        button.layer?.backgroundColor = NSColor.red.cgColor
    }
    
    var screen: NSScreen?
    
    @IBAction func didTapJoinRoom(_ sender: Any) {
        
        timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(updateSecond), userInfo: nil , repeats: true)
        //didTapButton()
    }
    
    @objc private func didTapButton() {
        
//        timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(updateSecond), userInfo: nil , repeats: true)
//
//        return
//         let vc = TTRoomViewController()
//         //vc.titleBarHeight = 44
//         let window = VNWindow(contentViewController: vc)
//         // window.isMove = false
//         window.titleBarHeight = 44
//         let minSize = CGSize(width: 1024, height: 580)
//         window.setContentSize(minSize)
//         window.makeKeyAndOrderFront(nil)
//         window.center()
//         view.window?.orderOut(nil)
         // window.zoom(nil)
         // window.styleMask = [.titled, .closable, .miniaturizable, .fullSizeContentView]

        
    
       // print(view.window?.tt_fromDisplayID )
        
//        let vc = TTTableViewController()
//        let window = TTWindow(contentViewController: vc)
//        //        window.isMove = false
//        window.tt_titleBarHeight = 44
//        let minSize = CGSize(width: 1024, height: 580)
//        window.setContentSize(minSize)
//        window.makeKeyAndOrderFront(nil)
//        window.center()
        //view.window?.orderOut(nil)
        
        
        let vc = WhiteboardViewController()
        let window = TTWindow(contentViewController: vc)
        window.tt_titleBarHeight = 100
        window.tt_isMove = false
        window.tt_beforeWindow = view.window
        window.styleMask = [.titled,
                            .closable,
                            .miniaturizable,
                            .resizable,
                            .fullSizeContentView]
        let rect = CGRect(x: 0, y: 0, width: 700, height: 500)
        //window.setFrameOrigin(CGPoint(x: 1024, y: 100))
        window.setContentSize(rect.size)
        window.center()
        window.makeKeyAndOrderFront(self)
        window.zoom(nil)
    }
    
    @objc private func didTapButton2() {
        print(className + " : " + #function)
    }
}
